	
	#delimit ;
		local vars 
			"married 
			hh_size 
			depressed
			healthinsurance_ever
			ill_inj
			ill_inj_stopactivity
			urban
			lives_alone
			work_any
			work_hrs
			diff_seei
			diff_hear
			diff_walk_clim
			diff_reme
			diff_self_care
			diff_comm
			disability
			notmarried";
	#delimit cr
	
	** Save data collapsed by age only
		** (for "aggregate" figures, black line with all-SSA average)
		
		** with weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars' [aw=weights_population5yr_survey], by(age_group5)
			save "$dir/data/allcountries_means5year_weightspopsurvey_all.dta", replace
			
		** no weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars', by(age_group5)
			save "$dir/data/allcountries_means5year_noweights_all.dta", replace
			
	** Save data collapsed by age and country
		** (for "aggregate" figures, grey lines with country-level averages)
	
		** with weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars' [aw=weights_population5yr_survey], by(age_group5 country)
			save "$dir/data/allcountries_means5year_weightspopsurvey_countries.dta", replace

		** no weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars', by(age_group5 country)
			save "$dir/data/allcountries_means5year_noweights_countries.dta", replace
	
	** Save data collapsed by age and gender
		** (for "country-level" figure, SSA average in first column)
	
		** with weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars' [aw=weights_population5yr_survey], by(age_group5 female)
			save "$dir/data/allcountries_means5year_weightspopsurvey.dta", replace
		
		** no weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars', by(age_group5 female)
			save "$dir/data/allcountries_means5year_noweights.dta", replace
			
	** Save data collapsed by age and country and gender
		** (for "country-level" figure, country-level averages in remaining columns)
	
		** with weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars' [aw=weights_population5yr_survey], by(age_group5 country female)
			save "$dir/data/allcountries_means5year_weightspopsurvey_countrygender.dta", replace
		
		** no weights
			use "$dir/data/allcountries.dta", clear
			drop if missing(female) | missing(age_group5)
			collapse (mean) `vars', by(age_group5 country female)
			save "$dir/data/allcountries_means5year_noweights_countrygender.dta", replace
